﻿using System;
using System.Collections.Generic;

using SBPweb.Forge.Contracts.Components;

using SBPweb.Communication.Shared.Library.Contacts;

namespace SBPweb.Communication.Shared.Library.Conversations
{

    public abstract class ConversationManagerBase : InitializableBase, IConversationManager
    {

        #region Protected fields

        protected MessengerBase messenger;
        protected Dictionary<IContact, IConversation> conversations;

        #endregion

        #region Constructor logic

        protected ConversationManagerBase(MessengerBase messenger)
        {
            this.messenger = messenger;
            this.conversations = new Dictionary<IContact, IConversation>();
        }

        #endregion

        #region Property accessors

        protected IMessenger Messenger
        {
            get
            {
                return messenger;
            }
        }

        public Dictionary<IContact, IConversation> Conversations
        {
            get
            {
                return conversations;
            }
        }

        public IConversationManagerConfiguration Configuration
        {
            get;
            protected set;
        }

        #endregion

        #region Events

        public event EventHandler<ConversationEventArgs> ConversationOpened;

        public event EventHandler<ConversationEventArgs> ConversationClosed;

        #endregion

        #region Methods

        #region Configuration

        public void ApplyConfiguration(IConversationManagerConfiguration configuration)
        {
            Configuration = configuration;
        }

        #endregion

        public abstract void OpenConversationWith(IContact contact);

        public abstract void OpenConference(string conferenceName);

        public abstract void OpenConference(IContact conferenceId);

        public abstract void OpenConference(string conferenceName, List<IContact> members);

        public abstract void OpenConference(IContact conferenceId, List<IContact> members);

        protected void OnConversationOpened(object sender, ConversationEventArgs e)
        {
            if (ConversationOpened != null)
            {
                ConversationOpened(sender, e);
            }
        }

        protected void OnConversationClosed(object sender, ConversationEventArgs e)
        {
            if (ConversationClosed != null)
            {
                ConversationClosed(sender, e);
            }
        }

        #endregion

    }

}